package com.heqiang.constant;


import com.heqiang.tools.MD5;
import com.heqiang.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.ResourceBundle;

public class Constant {


	public interface TABLE_NAME {
		String ADMIN = " admin ";
		String ROLE = " role ";

	}

	public static ResourceBundle rb = ResourceBundle.getBundle("application");
	public static Integer DAY = 365; // 一年天数
	public static String SESSION_KEY = "ADMIN";//session登录key
	public static String SUPER_MANAGER = "admin";
	public static String DEFAULT_TIME = "2000-01-01 00:00:00";
	public static String DEFAULT_PWD = "123456";
	public static String PWD_SUFFIX = "websiteuser";// 密码后缀
	public static Boolean ADMIN_FILTER_DEBUG = Boolean.valueOf(rb.getString("system.admin.filter.debug"));
	public static Boolean EXPORT_IS_LOCALHOST = Boolean.valueOf(rb.getString("system.export.is_localhost"));

	public interface FILE_PATH {
		String PNG = "/home/software/bx-file/png/";
		String LOCAL_EXCEL = "d://";

	}

	public interface FEIGN_AUTH {
		String HEADER_KEY = "FEIGN-AUTH-BX";
		String ORDER = rb.getString("feign.auth.order");
	}


	// 中文乱码
	public static String getChinese(String str) {
		String nameStr = "";
		if(StringUtils.isBlank(str)){
		    return "";
        }
		try {
		    if(str.equals(new String(str.getBytes("ISO-8859-1"), "UTF-8"))){
                nameStr = new String(str.getBytes("ISO-8859-1"), "UTF-8");
            }
            if(str.equals(new String(str.getBytes("UTF-8"), "UTF-8"))){
                nameStr = new String(str.getBytes("UTF-8"), "UTF-8");
            }
		} catch (UnsupportedEncodingException e) {
		}
		return StringUtils.isBlank(nameStr)?str:nameStr;
	}

	public interface SMS_TEMPLATE_INDEX {
		Byte DROPLINE = (byte) 10;// 掉线
		Byte BATTERY = (byte) 20;// 电量
		Byte CARD = (byte) 30;// 卡纸
		Byte LESS = (byte) 40;// 少纸
		Byte EMPTY = (byte) 50;// 空纸
		Byte TRACK = (byte) 60;// 断纸
	}


	/**
	 *  	获取密码的加密字符串
	 * xiesanchuan
	 * @param pwd
	 * @param isEncrypt
	 * @return
	 * 2019年9月19日
	 */
	public static String getPwd(String pwd, Boolean isEncrypt, Integer nums) {
		pwd = pwd + PWD_SUFFIX;
		if (null == isEncrypt || !isEncrypt) {
			return pwd;
		}
		if (null == nums || nums == 1) {
			return MD5.parseMD5(pwd);
		}
		Assert.state(nums == 2, "次数有问题");
		return MD5.parseMD5(MD5.parseMD5(pwd));
	}

	public static Date getDefaultTime() {
		return DateUtils.StringToDate(DEFAULT_TIME, DateUtils.formatStr_yyyyMMddHHmmss);
	}

}
